﻿using System;

using MosCraft.Utilities;

namespace MosCraft.Blocks
{
    class BlockReed : Block
    {
        public BlockReed(int id)
            : base(id, 73, Material.Plants)
        {
            float offset = 0.375F;
            setBlockBounds(0.5F - offset, 0.0F, 0.5F - offset, 0.5F + offset, 1.0F, 0.5F + offset);
        }

        public override RenderMode getRenderType()
        {
            return RenderMode.CROSS;
        }

        public override bool RenderOpposites()
        {
            return true;
        }

        internal override bool renderAsNormalBlock()
        {
            return false;
        }

        public override AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
        {
            return null;
        }

        public override bool canBlockStay(World world, int x, int y, int z)
        {
            int blockAt = world.getBlockID(x, y - 1, z);

            if (blockAt == base.blockID)
            {
                return true;
            }

            if (world.getBlockMaterial(x, y, z) == Material.Water)
            {
                return false;
            }

            if ((blockAt == Block.Sand.blockID || blockAt == Block.Grass.blockID) &&
                (world.getBlockMaterial(x - 1, y - 1, z) == Material.Water ||
                world.getBlockMaterial(x + 1, y - 1, z) == Material.Water ||
                world.getBlockMaterial(x, y - 1, z - 1) == Material.Water ||
                world.getBlockMaterial(x, y - 1, z + 1) == Material.Water))
            {
                return true;
            }

            return false;
        }
    }
}
